package se.jocke.tg;

import org.openide.util.lookup.ServiceProvider;

/**
 *
 * @author jocke
 */
@ServiceProvider(service=EditorStringFormater.class)
public class DefaultEditorStringFormater implements EditorStringFormater {

    @Override
    public String formatStringBuilderString(String[] textRows) {
        StringBuilder builder = new StringBuilder("StringBuilder builder = new StringBuilder();\n");
        for (int i = 0; i < textRows.length; i++) {
            builder.append("builder.append(")
                   .append("\"")
                   .append(textRows[i].trim())
                   .append("\"")
                   .append(").append(\"\\n\");\n");
        }
        return builder.toString();
    }

    @Override
    public String formatCommentString(String[] textRows) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < textRows.length; i++) {
            builder.append("//").append(textRows[i].trim()).append("\n");
        }
        return builder.toString();
    }

    @Override
    public String formatDefaultString(String[] textRows) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < textRows.length; i++) {
            builder.append('"').append(textRows[i].trim()).append('"').append("\n");
            if (notLastRow(i, textRows)) {
                builder.append("+");
            }
        }
        return builder.toString();
    }

    private boolean notLastRow(int inde, String[] textRows) {
        return inde != textRows.length - 1;
    }
}
